<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="年度：">
          <el-select v-model="listPram.year" placeholder="年度" clearable class="selWidth">
            <el-option
                v-for="item in yearList"
                :key="item"
                :label="item"
                :value="item"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="handlerOpenEdit(0)" v-hasPermi="['admin:fund:process:save']">添加</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" class="table" v-loading="loading" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column
          prop="id"
          label="ID"
          width="50"
        />
        <el-table-column
            prop="year"
            label="年度"
            min-width="80"
        />
        <el-table-column
            prop="department"
            label="所属单位"
            min-width="120"
        />
        <el-table-column
            prop="amount"
            label="金额(万元)"
            min-width="100"
        />
        <el-table-column
            prop="finishTime"
            label="完成时间"
            min-width="100"
        />
        <el-table-column prop="description" label="备注" min-width="200" >
          <template slot-scope="scope">
            <div class="content" :class="{showMore:!scope.row.show}" :title="scope.row.content">{{scope.row.content | filterEmpty}}</div>
            <span @click="showMore(scope.row,true)" v-show="!scope.row.show && scope.row.content" style="color:#0080ff;cursor:pointer;">显示更多</span>
            <span @click="showMore(scope.row,false)" v-show="scope.row.show && scope.row.content" style="color:#0080ff;cursor:pointer;">收起</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="130" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" type="primary" size="mini" @click="handlerOpenEdit(1,scope.row)" v-hasPermi="['admin:fund:process:info']">编辑</el-button>
            <el-button icon="el-icon-delete" type="danger" size="mini" @click="handlerOpenDel(scope.row)" v-hasPermi="['admin:fund:process:delete']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :layout="constants.page.layout"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <!--新增/编辑-->
    <el-dialog
      :visible.sync="editDialogConfig.visible"
      :title="editDialogConfig.isCreate === 0? '创建争取资金完成情况':'编辑争取资金完成情况'"
      destroy-on-close
      :close-on-click-modal="false"
    >
      <edit
        v-if="editDialogConfig.visible"
        :is-create="editDialogConfig.isCreate"
        :edit-data="editDialogConfig.editData"
        :all-year-list="yearList"
        :all-department-list="departmentList"
        @hideEditDialog="hideEditDialog"
      />
    </el-dialog>
  </div>
</template>

<script>
import * as projectApi from '@/api/projectApi.js'
import * as fundApi from '@/api/fundApi.js'
import edit from './edit'
import { checkPermi } from "@/utils/permission";
import * as selfUtil from "@/utils/ZBKJIutil";
import * as categoryApi from "@/api/categoryApi";
import {staticCategoryList, staticGuaranteeMethodList, staticProjectStatusList, staticTypeList} from '@/utils/constants'
import {Debounce} from "@/utils/validate";
import Tinymce from '@/components/Tinymce/index'
import {processDel} from "@/api/fundApi.js";
export default {
  // name: "index"
  components: { edit },
  data() {
    return {
      constants:this.$constants,
      loading:false,
      listData: { list: [] },
      listPram: {
        year:'',
        keyword: '',
        /*ipAddress: null,
        macAddress: null,
        personId: null,*/
        page: 1,
        limit: this.$constants.page.limit[0]
      },
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        editData: {}
      },
      yearList:[],
      departmentList:[],
      id:0,
      Visible:false,
    }
  },
  mounted() {
    this.handleGetProcessList()
    this.initYearList()
    this.initDepartmentList()
  },
  methods: {
    checkPermi,
    //控制长文本显示和收起
    showMore (row, flag) {
      this.$set(row,'show',flag)
    },

    handleSearch() {
      this.listPram.page = 1
      this.handleGetProcessList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.handleGetProcessList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.handleGetProcessList()
    },
    handlerOpenDel(rowData) {
      this.$confirm('确认删除当前数据').then(() => {
        const _pram = { id: rowData.id}
        fundApi.processDel(_pram).then(data => {
          this.$message.success('删除数据成功')
          this.handleGetProcessList()
        })
      })
    },
    initYearList(){
      this.loading = true

      let myDate = new Date();
      let thisYear = myDate.getFullYear();
      for (let i=0;i<5;i++){
        this.yearList.push(thisYear-i)
      }
      this.loading = false
    },
    initDepartmentList(){
      this.loading = true

      projectApi.getDepartmentOption().then(data => {
        this.departmentList = data
        this.loading = false
      }).catch(()=>{
        this.loading = false
      })
    },
    handleGetProcessList() {
      fundApi.getProcessList( this.listPram ).then(data => {
        /*let data = {"page":1,"limit":15,"totalPage":1,"total":2,"list":[
          {"id":1,"year":2023,"departmentId":3,"departmentName":"发改局","content":"深入学习贯彻习近平新时代中国特色社会主义思想，坚持读原著、学原文、悟原理，做到自觉主动学、及时跟进学、联系实际学、笃信笃行学，着力在全面学习、全面掌握、全面落实上下功夫，深刻领悟“两个确立”的决定性意义，增强“四个意识”、坚定“四个自信” 做到“两个维护”，深入开展“三抓三促”行动，坚持以上率下、坚持问题导向、坚持求真务实、坚持系统观念，着力解决理论武装不深、知识储备不足、学用结合不紧等突出问题，不断提高科学判断形势的能力，驾驭经济的能力，应对复杂局面的能力，并结合发改部门行业特点，营造比学赶超、争先进位的浓厚氛围，切实把学习成果转化为工作举措和实际成效，以实际行动为瓜州经济贡献发改力量。","process":"注重将党的二十大精神、习近平新时代中国特色社会主义思想、习近平总书记关于本领域本行业工作的重要论述等党的创新理论，省市县委重大决策部署要求作为学习的主要内容，督促全体干部职工采取班子成员领学、党支部研学、党员干部自学,推动党员干部真正把学习抓在经常、融入日常。扎实开展“素质能力强化百日攻坚”行动，针对领导干部素质偏低不想为、能力不强不敢为、本领弱化不善为等问题，结合干部职工例会、业务学习会议等，每周组织开展一次系统业务学习、每周开展一次学习检验、每月开展一次考核评比，着力补齐干部职工素质能力短板，强化敢为人先、善作善成的本领，教育引导干部职工争做熟悉政策的“政策通”、服务发展的“业务通”攻坚克难的“多面手”。","amount":30,"finishTime":"2023-04-06"},
          {"id":2,"year":2023,"departmentId":14,"departmentName":"交通局","content":"深入学习贯彻习近平新时代中国特色社会主义思想，坚持读原著、学原文、悟原理，做到自觉主动学、及时跟进学、联系实际学、笃信笃行学，着力在全面学习、全面掌握、全面落实上下功夫，深刻领悟“两个确立”的决定性意义，增强“四个意识”、坚定“四个自信” 做到“两个维护”，深入开展“三抓三促”行动，坚持以上率下、坚持问题导向、坚持求真务实、坚持系统观念，着力解决理论武装不深、知识储备不足、学用结合不紧等突出问题，不断提高科学判断形势的能力，驾驭经济的能力，应对复杂局面的能力，并结合发改部门行业特点，营造比学赶超、争先进位的浓厚氛围，切实把学习成果转化为工作举措和实际成效，以实际行动为瓜州经济贡献发改力量。","process":"注重将党的二十大精神、习近平新时代中国特色社会主义思想、习近平总书记关于本领域本行业工作的重要论述等党的创新理论，省市县委重大决策部署要求作为学习的主要内容，督促全体干部职工采取班子成员领学、党支部研学、党员干部自学,推动党员干部真正把学习抓在经常、融入日常。扎实开展“素质能力强化百日攻坚”行动，针对领导干部素质偏低不想为、能力不强不敢为、本领弱化不善为等问题，结合干部职工例会、业务学习会议等，每周组织开展一次系统业务学习、每周开展一次学习检验、每月开展一次考核评比，着力补齐干部职工素质能力短板，强化敢为人先、善作善成的本领，教育引导干部职工争做熟悉政策的“政策通”、服务发展的“业务通”攻坚克难的“多面手”。","amount":100,"finishTime":"2023-04-06"},
        ]}*/
        this.listData = data
      })
    },

    handlerOpenEdit(isCreate,editDate) {
      this.editDialogConfig.isCreate = isCreate
      this.editDialogConfig.editData = editDate
      this.editDialogConfig.visible = true
    },
    hideEditDialog() {
      this.editDialogConfig.visible = false
      this.handleGetProcessList()
    },
    resetQuery(){
      this.listPram.year = ''
      this.listPram.keyword = '';
      this.handleGetProcessList()
    },
  }
}
</script>

<style scoped lang="scss">
  .table .showMore{
    display:block;
    width:100%;
    word-break:keep-all;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
</style>
